<?php
declare (strict_types=1);

namespace app\api\controller;

use think\facade\View;
use think\response\Json;
use app\common\model\Draw as DrawModel;
use think\exception\ValidateException;

class Draw extends Base
{

    public function index()
    {
        $result['draw_account'] = [
            [
                'title' => '奖金',
                'type' => 'bonus',
                'balance' => $this->user->assets->bonus
            ],
        ];
        $result['draw_factor'] = [
            'draw_open' => $this->system['draw_open'],
            'draw_cost' => $this->system['draw_cost'],
            'draw_bs' => $this->system['draw_bs'],
            'draw_min' => $this->system['draw_min'],
            'draw_msg' => $this->system['draw_msg'],
        ];
        $result['user_method'] = [
            [
                'mode' => '支付宝',
                'name' => $this->user->alipay_name,
                'image' => handleImg($this->user->alipay_image),
            ],
            [
                'mode' => '微信',
                'name' => $this->user->wechat_name,
                'image' => handleImg($this->user->wechat_image),
            ],
            [
                'mode' => '银行卡',
                'bank_name' => $this->user->bank_name,
                'bank_open' => $this->user->bank_open,
                'bank_account_name' => $this->user->bank_account_name,
                'bank_number' => $this->user->bank_number,
            ],
        ];
        return json(['code' => 1, 'msg' => 'success', 'result' => $result]);
    }


    public function getList(): Json
    {
        $param = $this->request->param();

        $map = ['uid' => $this->user->id, 'is_del' => 0];

        return json(DrawModel::getPageList($map, 'id,account,mode,money,cost,amount,reject_msg,
        create_time,status', $param['page'], 20, false));
    }

    public function save(): Json
    {
        $param = $this->request->post('', '', $this->filter);
        try {
            $this->validate($param, 'Draw');
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }
        return json(DrawModel::add($param, $this->user, $this->system));
    }

}

